<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/9
 * Time: 14:23
 */

namespace App\Http\Controllers\Account;


use App\Http\Controllers\Controller;
use App\Model\Account\TypeDetail;
use App\Http\Controllers\Validator\TypeVail;
use App\Tool\Error;
use Illuminate\Http\Request;

class TypeDetailController extends Controller
{
        protected $typeDetail;

        public function __construct()
        {
            $this->typeDetail = new TypeDetail();
        }
        //分类下的种类列表
        public function typeDetailList(Request $request)
        {
            if (!$request->has('td_id')) {
                return $this->error(Error::PARAM_MISSING);
            }
            $params = $request->all();
            $where[] = ['td.td_tid', $params['td_id']];
            //类型状态名字
            if ($request->input('td_name')){
                $where[] = ['td_name', 'like', "%".$params['td_name']."%"];
            }
            $list = $this->typeDetail->typeDetailList(env('PAGE_LIMIT_ADMIN'), $where);
            if (!$list) {
                return $this->error(Error::NULL_DATA);
            }
            return $this->success('ok', $list);
        }

        //添加分类状态
        public function typeDetailAdd(Request $request)
        {
            $params = $request->all();
            $vali =TypeVail::addTypeDetail($params);
            if(!$vali){
                return $this->error(Error::PARAM_MISSING);
            }
            $status = $this->typeDetail->typeDetailAdd($params);
            if (!$status) {
                return $this->error(Error::ADD_ERROR);
            }
            return $this->success('ok', '添加成功');
        }

        //修改分类状态
        public function typeDetailEdit(Request $request)
        {
            $params = $request->all();
            $vali =TypeVail::editTypeDetail($params);
            if(!$vali){
                return $this->error(Error::PARAM_MISSING);
            }
            $status = $this->typeDetail->typeDetailEdit($params);
            if (!$status) {
                return $this->error(Error::EDIT_ERROR);
            }
            return $this->success('ok', '修改成功');
        }


        //删除分类状态
    public function typeDetailDel(Request $request)
    {
        $params = $request->all();
        $vali =TypeVail::delTypeDetail($params);
        if(!$vali){
            return $this->error(Error::PARAM_MISSING);
        }
        $status = $this->typeDetail->typeDetailDel($params);
        if (!$status) {
            return $this->error(Error::DEL_ERROR);
        }
        return $this->success('ok', '删除成功');
    }
}